﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;

public partial class user_favimg_det : System.Web.UI.Page
{
    public a_Articles_ImgCollection imgs;
    public a_AlbumCollection albums;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request["a"] != null && Request["a"] == "del")
            {
                //delete a_Favorites by IID,SSID,AlbumID
                a_FavoriteService.Deletea_FavoriteImg(int.Parse(Request["39947"]), SessionManager.GetCookie(), int.Parse(Request["9612"]));
                msg.InnerHtml = "Đã xóa hình trong album!";
                msg.Visible = true;
            }
            if (Request["alid"] != null)
            {
                int alid = int.Parse(Request["alid"]);
                Paging1.PerPage = 8;
                int total;
                imgs = a_Articles_ImgService.Geta_Articles_ImgListFav(alid, a_Articles_ImgColumns.IID, ThoiTrang.Data.OrderDirection.ASC, Paging1.CurPage, Paging1.PerPage, out total);
                Paging1.Total = total;
                if (imgs == null || imgs.Count==0)
                {
                    msg.InnerHtml = "Bạn chưa thêm hình vào album này!";
                    msg.Visible = true;
                }
                albums = a_AlbumService.Geta_AlbumListBySSID(SessionManager.GetCookie(), a_AlbumColumns.Name, ThoiTrang.Data.OrderDirection.ASC);
            }
            else
            {
                msg.InnerHtml = "Album không hợp lệ!";
                msg.Visible = true;
            }
        }
        catch (Exception ex)
        {
            msg.InnerHtml = ex.Message;
            msg.Visible = true;
        }
    }
    public string GetImageLink(a_Articles_Img Img)
    {
        a_Article aTemp = a_ArticleService.Geta_Article(Img.AID);
        return FOConstants.Dir_ImgArticle + aTemp.KTitle.Replace(' ', '-') + "-" + Img.FYear.ToString() + "-" + "d" + Img.AID.ToString() + Img.ImageNo.ToString() + ".jpg";
    }
    public string GetParameterIn(a_Articles_Img Img)
    {
        a_Article aTemp = a_ArticleService.Geta_Article(Img.AID);
        return aTemp.KTitle.Replace(' ', '-') + "-" + Img.FYear.ToString() + "-" + "d" + Img.AID.ToString() + Img.ImageNo.ToString() + ".jpg";
    }
    public int CountImg(int abId)
    {
        a_FavoriteCollection favs = a_FavoriteService.Geta_FavoriteListByAlbumID(abId, a_FavoriteColumns.ID, ThoiTrang.Data.OrderDirection.ASC);
        return favs == null ? 0 : favs.Count;
    }
}
